//
//  XMLanuchPlaceViewController.m
//  XunMi
//
//  Created by MacBook on 2024/4/2.
//  Copyright © 2024 TieZhu. All rights reserved.
//

#import "XMLanuchPlaceViewController.h"
#import "XMLanuchAgreementTipView.h"

@interface XMLanuchPlaceViewController ()<XMLanuchAgreementTipViewDelegate>

@end

@implementation XMLanuchPlaceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self jailBreak];
    [self requestNetwork];
    [self setupSubviews];
}

#pragma mark - setupSubViews
- (void)setupSubviews {
    self.navView.hidden = YES;
    BOOL agree = [kMMKV getBoolForKey:@"agree"];
    if (agree) {
        if (self.enterBlock) {
            self.enterBlock();
        }
    } else {
        XMLanuchAgreementTipView *view = [XMLanuchAgreementTipView viewFromXib];
        view.delegate = self;
        view.size = CGSizeMake(325, 325 * 4 / 3);
        [GKCover coverFrom:self.view contentView:view style:(GKCoverStyleTranslucent) showStyle:(GKCoverShowStyleCenter) showAnimStyle:(GKCoverShowAnimStyleNone) hideAnimStyle:(GKCoverHideAnimStyleNone) notClick:YES];
    }
}

- (void)lanuchAgreeClick {
    [kMMKV setBool:YES forKey:@"agree"];
    if (self.enterBlock) {
        self.enterBlock();
    }
}

- (void)lanuchNotAgreeClick {
    exit(0);
}

- (void)lanuchProtocolClick {
    XMWebViewController *vc = [[XMWebViewController alloc] init];
    vc.title = @"用户协议";
    vc.urlStr = kGlobalVariables.appConfig.privacy.serviceAgreement;
    vc.needNav = YES;
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)lanuchPrivacyClick {
    XMWebViewController *vc = [[XMWebViewController alloc] init];
    vc.title = @"隐私政策";
    vc.urlStr = kGlobalVariables.appConfig.privacy.privacyAgreement;
    vc.needNav = YES;
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)jailBreak {
    if ([XMUtil isJailBreak]) {
        exit(0);
    }
}

- (void)requestNetwork {
    NSURL *url = [NSURL URLWithString:@"https://www.baidu.com"];
    NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
    NSURLSession *session = [NSURLSession sharedSession];

    NSURLSessionDataTask *task = [session dataTaskWithRequest:request
                                            completionHandler:^(NSData *_Nullable data, NSURLResponse *_Nullable response, NSError *_Nullable error){
                                            }];
    [task resume];
}


@end
